Back to Main Menu

Create Work Order (Assetic Python SDK)

Introduction

The Assetic Python SDK may be used to simplify creation of a Work Order.

Review the integration article Create Work Order to understand the purpose of each field, typical default values, and typical integration payloads.

Code Samples

The following example creates a new "INPRG" work order using the Assetic Python SDK.

  1. """
  2. Example script to create work order (Assetic.WorkOrderPost.py)
  3. """
  4. import assetic
  5. # create an authentication connection with the Assetic environment
  6. asseticsdk = assetic.AsseticSDK(None, None, 'Info')
  7. asseticsdk.logger_format = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s"
  8. # create the API connection to the maintenance work order endpoints
  9. work_order_api = assetic.WorkOrderApi()
  10. # create the Work Order model object
  11. maint_wko = assetic.models.MaintenanceWorkOrder()
  12. maint_wko.status = "INPRG"
  13. maint_wko.brief_description = "Potholes in Sussex Street"
  14. maint_wko.priority_id = 2
  15. maint_wko.estimated_duration = 3
  16. maint_wko.location_description = "20, Sussex Street, Glenorchy, TAS, 7010, Australia"
  17. maint_wko.point_string = "147.26314791653294 -42.832066858923795"
  18. maint_wko.creator_id = "36bee8ab-4e39-4f1d-b713-4eefa521fcd8"
  19. maint_wko.requestor_id = "8d05ef3b-5da4-e511-9451-06edd62954d7"
  20. # Specify the work type to the Work Order
  21. wko_type = assetic.models.WorkType()
  22. wko_type.id = 6
  23. maint_wko.work_order_type = wko_type
  24. # based on work type requirements, specify the FCR codes
  25. maint_wko.failure_sub_code_id = 1
  26. maint_wko.cause_sub_code_id = 1
  27. maint_wko.remedy_code_id = 2
  28. # assign an Assetic asset by referencing its internal ID (GUID)
  29. maint_wko.asset_id = "6216b184-62b0-e611-946c-06edd62954d7"
  30. maint_wko.work_order_work_group = "Indoor Crew 1"
  31. # add 1 (or more) supporting information comments as a list to the work order
  32. suppinfolist = list()
  33. suppinfo = assetic.models.SupportingInformation()
  34. suppinfo.description = "Long description 1 goes here."
  35. suppinfolist.append(suppinfo)
  36. suppinfo = assetic.models.SupportingInformation()
  37. suppinfo.description = "Long description 2 goes here."
  38. suppinfolist.append(suppinfo)
  39. maint_wko.supporting_information = suppinfolist
  40. # add a labour item to the work order
  41. labour_list = list()
  42. labour = assetic.models.MaintenanceLabour()
  43. labour.planned_group_craft_id = "5379a3df-feb1-e611-946c-06edd62954d7"
  44. labour.quantity_required = 1
  45. labour.hours_required = 3
  46. # create a maintenance resource object for the maintenance resource properties
  47. maint_resource_list = list()
  48. maint_resource = assetic.models.MaintenanceResource()
  49. # specify an Assetic resource entity to be assigned to the maintenance resourcelabour
  50. resource = assetic.models.ResourceRepresentation()
  51. resource.id = "66554e3b-ed60-4036-8552-1cdac380fffb"
  52. maint_resource.resource = resource
  53. # set the resources work status (assign/completed), which labor they are assigned to, etc
  54. maint_resource.status_id = 1
  55. maint_resource.assigned_group_craft_id = "5379a3df-feb1-e611-946c-06edd62954d7"
  56. # maint_resource.actual_start = "2017-11-19T16:04:56"
  57. # maint_resource.actual_finish = "2017-11-20T16:04:56"
  58. maint_resource_list.append(maint_resource)
  59. labour.maintenance_resources = maint_resource_list
  60. labour_list.append(labour)
  61. maint_wko.labours = labour_list
  62. # Add target and scheduling dates to the work order
  63. schedule = assetic.models.MaintenanceScheduling()
  64. schedule.target_start = "2024-08-04T09:04:56"
  65. schedule.target_finish = "2024-08-09T12:04:56"
  66. schedule.scheduled_start = "2024-08-05T00:00:00"
  67. schedule.scheduled_finish = "2024-08-09T00:00:00"
  68. # if creating a work order that is in a completed state, set the actual starts and finishes below
  69. # schedule.actual_start = "2017-11-19T16:04:56"
  70. # schedule.actual_finish = "2017-11-20T16:04:56"
  71. maint_wko.scheduling = schedule
  72. # add materials to the work order
  73. materials_list = list()
  74. material = assetic.models.MaintenanceMaterial()
  75. material.bill_of_material_id = "2b4f13ce-673d-41da-ac72-74f05460fab5"
  76. material.is_material_available = True
  77. material.planned_quantity = 1
  78. materials_list.append(material)
  79. maint_wko.maintenance_materials = materials_list
  80. # add any services to work order
  81. services_list = list()
  82. service = assetic.models.MaintenanceService()
  83. service.service_activity_id = "ab08efe6-b41e-4e60-8f7b-9ab4daaf6ecc"
  84. service.description = "Pothole repair"
  85. # service.unit_type = "Each"
  86. service.planned_quantity = 2
  87. service.planned_cost = 100
  88. service.actual_quantity = 5
  89. service.actual_unit_rate = 15
  90. services_list.append(service)
  91. maint_wko.maintenance_services = services_list
  92. # add a work task related to the work order labor item
  93. tasks_list = list()
  94. task = assetic.models.MaintenanceWorkTask()
  95. task.friendly_id = 10
  96. task.brief_description = "Task to patch pothole"
  97. task.status = 5
  98. tasks_list.append(task)
  99. # add an asessment work task to the work order with an attached custom assessment form
  100. task = assetic.models.MaintenanceWorkTask()
  101. task.friendly_id = 20
  102. task.brief_description = "Assessment task with checklist following repair"
  103. task.status = 5
  104. task.type_id = 201
  105. task_forms = list()
  106. form = assetic.models.AsmtTaskFormRepresentation()
  107. form.form_id = "71806f28-d1ee-42e6-a1d2-40f6f955c54d"
  108. form.form_result_count = 0
  109. form.minimum = 1
  110. form.maximum = 1
  111. form.order = 0
  112. task_forms.append(form)
  113. task.asmt_task_forms = task_forms
  114. tasks_list.append(task)
  115. maint_wko.work_tasks = tasks_list
  116. # initiate the request to the Assetic REST API
  117. try:
  118. response = work_order_api.work_order_integration_api_post(maint_wko)
  119. except assetic.rest.ApiException as e:
  120. asseticsdk.logger.error('Status {0}, Reason: {1}'.format(e.status,e.reason))
  121. except Exception as e:
  122. asseticsdk.logger.error(str(e))
  123. else:
  124. asseticsdk.logger.info(str(response))